package com.xy.controller;

import javax.servlet.http.HttpSession;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.xy.constant.Constant;
import com.xy.entity.User;
import com.xy.service.UserService;
import com.xy.util.PropertiesUtil;

/**
 * 登陆用户控制层
 * 
 * @author 陈耀
 * @date 2018-2-1
 */
@Controller
@Scope
public class UserController {
	private Logger log = Logger.getLogger(UserController.class);
	@Autowired
	private UserService userService;

	/**
	 * 登陆用的
	 * 
	 * @param user
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "login", method = RequestMethod.POST)
	public String loginUser(User user, HttpSession httpSession) {
		user = userService.loginUser(user);
		if (user == null) {
			return "pages/backend/login.jsp";
		}
		httpSession.setAttribute("user", user);
		log.info("session:" + httpSession.getAttribute("user"));
		httpSession.setAttribute("resourse", PropertiesUtil.getValue(Constant.TOMCAT_PATH));
		return "pages/backend/main.jsp";
	}

}
